{% extends "base_generic.html" %}
{% load static %}
{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/user_management.css' %}">
{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header bg-danger text-white">
            <h1 class="mb-0"><i class="fas fa-user-minus"></i> 删除作者: {{ author }}</h1>
        </div>
        <div class="card-body">
            {% if author.book_set.all %}
            <div class="alert alert-warning">
                <p>在删除该作者之前，请先删除其所有书籍：</p>
                <ul class="list-group">
                    {% for book in author.book_set.all %}
                    <li class="list-group-item">
                        <a href="{% url 'book-detail' book.pk %}">{{book}}</a> ({{book.bookinstance_set.all.count}})
                    </li>
                    {% endfor %}
                </ul>
            </div>
            {% else %}
            <div class="alert alert-danger">
                <p>确定要删除该作者吗？</p>
            </div>
            <form action="" method="POST">
                {% csrf_token %}
                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                    <a href="{% url 'authors' %}" class="btn btn-secondary me-md-2">取消</a>
                    <button type="submit" class="btn btn-danger">确认删除</button>
                </div>
            </form>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}